package com.guard.ui;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.guard.R;
import com.guard.android.GuardManager;
import com.guard.net.HttpConnectionError;

public class InformationActivity extends AbstractActivity {
    private TextView cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info_activity);
    }

    @Override
    protected void onResume() {
        super.onResume();
        init();
    }
    
    @Override
    public void onBackPressed() {
        System.out.println("OLEG: InformationActivity.onBackPressed ");
    }

    private void init() {
        cancel = (TextView) findViewById(R.id.cancel);
        cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                sendCancel();
            }
        });

    }

    private void sendCancel() {
        new AsyncTask<Void, Boolean, Boolean>() {

            private Exception mException = null;

            @Override
            protected Boolean doInBackground(Void... params) {
                Boolean result = Boolean.FALSE;
                try {
                    result = GuardManager.instance().cancel();
                } catch (HttpConnectionError e) {
                    mException = e;
                }
                return result;
            }

            protected void onPostExecute(Boolean result) {
                if (result) {
                    showToast(getResources().getString(R.string.order_send));
                } else {
                    showToast(getResources().getString(R.string.order_not_send));
                }
                if (mException != null) {
                    showConnectionErrorDialog();
                }
            };

        }.execute((Void) null);
    }

}
